package org.crystal.tradecraft.model.binance.param;

import lombok.Builder;
import org.crystal.tradecraft.model.binance.enumeration.OrderResponseType;
import org.crystal.tradecraft.model.binance.enumeration.OrderSide;
import org.crystal.tradecraft.model.binance.enumeration.OrderType;
import org.crystal.tradecraft.model.binance.enumeration.STPMode;
import org.crystal.tradecraft.model.binance.enumeration.TimeInForce;

import java.util.HashMap;
import java.util.Map;

@Builder
public record NewOrder(
    String symbol,
    OrderSide side,
    OrderType type,
    TimeInForce timeInForce,
    Double quantity,
    Double quoteOrderQty,
    Double price,
    String newClientOrderId,
    Integer strategyId,
    Integer strategyType,
    Double stopPrice,
    Long trailingDelta,
    Double icebergQty,
    OrderResponseType newOrderRespType,
    STPMode selfTradePreventionMode,
    Long recvWindow,
    long timestamp
) {
    public Map<String, Object> toMap() {
        return toMap(false);
    }

    public Map<String, Object> toMap(boolean computeCommissionRates) {
        Map<String, Object> paramMap = new HashMap<>(18);
        paramMap.put("symbol", symbol);
        paramMap.put("side", side.name());
        paramMap.put("type", type.name());
        paramMap.put("timestamp", timestamp);

        paramMap.put("timeInForce", timeInForce);
        paramMap.put("quantity", quantity);
        paramMap.put("quoteOrderQty", quoteOrderQty);
        paramMap.put("price", price);
        paramMap.put("newClientOrderId", newClientOrderId);
        paramMap.put("strategyId", strategyId);
        paramMap.put("strategyType", strategyType);
        paramMap.put("stopPrice", stopPrice);
        paramMap.put("trailingDelta", trailingDelta);
        paramMap.put("icebergQty", icebergQty);
        paramMap.put("newOrderRespType", newOrderRespType.name());
        paramMap.put("selfTradePreventionMode", selfTradePreventionMode.name());
        paramMap.put("recvWindow", recvWindow);

        if (computeCommissionRates) paramMap.put("computeCommissionRates", true);

        return paramMap;
    }
}
